package com.campus.expression;

import com.campus.domain.dto.UserDTO;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("ex")
public class SGExpressionRoot {

    public boolean hasAuthority(String authority) {
        // 从当前登录用户中获取权限
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        UserDTO userDTO = (UserDTO)authentication.getPrincipal();
        List<String> permissions = userDTO.getPermissions();
        //判断用户权限几个中是否存在authority
        return permissions.contains(authority);
    }
}
